package com.whj.apipassenger.controller;

import com.whj.apipassenger.request.CheckVerificationCodeDTO;
import com.whj.apipassenger.request.SendVerificationCodeDTO;
import com.whj.apipassenger.service.VerificationCodeService;
import com.whj.internalcommon.dto.ResponseResult;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Auther: wanghaijun
 * @Date: 2022/12/25 - 12 - 25 - 16:48 
 * @Description: com.whj.apipassenger.controller
 */

@RestController
public class VerificationCodeController {


    @Autowired
    private VerificationCodeService verificationCodeService;

    /**
     * 验证验证码
     *
     * @param verificationCodeDTO
     * @return
     */
    @PostMapping("/verification-code")
    public ResponseResult verificationCode(@Validated @RequestBody SendVerificationCodeDTO verificationCodeDTO) {
        return verificationCodeService.generatorCode(verificationCodeDTO.getPassengerPhone());
    }

    /**
     * 校验验证码
     *
     * @param checkVerificationCodeDTO
     * @return
     */
    @PostMapping("/verification-code-check")
    public ResponseResult checkVerificationCode(@Validated @RequestBody CheckVerificationCodeDTO checkVerificationCodeDTO) {

        String passengerPhone = checkVerificationCodeDTO.getPassengerPhone();
        String verificationCode = checkVerificationCodeDTO.getVerificationCode();
        System.out.println("passengerPhone = " + passengerPhone);
        System.out.println("verificationCode = " + verificationCode);
        return verificationCodeService.checkCode(passengerPhone, verificationCode);
    }
}
